package com.ayou.eggguard.farm.mapper;

import com.ayou.eggguard.farm.pojo.ChickenFarm;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ChickenFarmMapper {
    @Select("select * from chickenfarm where farm_name=#{farmName}")
    ChickenFarm getFarmByName(String farmName);

    @Insert("insert into chickenfarm(farm_name, address, contact, manager, longitude, latitude, scale) " +
            "values (#{farmName},#{address},#{contact},#{manager},#{longitude},#{latitude},#{scale})")
    void addFarm(ChickenFarm chickenFarm);

    @Update("update chickenfarm set address=#{address},contact=#{contact}," +
            "manager=#{manager},longitude=#{longitude},latitude=#{latitude},scale=#{scale} " +
            "where farm_name=#{farmName}")
    void updateFarm(ChickenFarm chickenFarm);

    @Select("select * from chickenfarm")
    List<ChickenFarm> getAllFarm();

    @Select("select chickenfarm.farm_id from chickenfarm where farm_name=#{farmName}")
    int getFarmIdByFarmName(String farmName);
}
